<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>公寓管理</title>
</head>
<body>
<div class="page-container">
    <div class="mt-20">
        <table class="table table-border table-bordered table-bg table-sort" id="list">
            <!--<thead>
                   <tr class="text-c">
                   <th width="25"><input type="checkbox" name="" value=""></th>
                   <th width="70">ID</th>
                   <!--<th width="80">排序</th>
                   <th width="240">名字</th>
                   <th>公寓财产</th>
                   <th>操作</th>
                   <!--<td><input type="text" class="input-text text-c" value="1"></td>
                   <td><img src="temp/brand/dongpeng.jpeg"></td>
                   <td class="text-l"><img title="国内品牌" src="static/h-ui.admin/images/cn.gif"> 东鹏</td>
                   <td class="text-l">东鹏陶瓷被评为“中国名牌”、“国家免检产品”、“中国驰名商标”、http://www.dongpeng.net/</td>
                   <td class="f-14 product-brand-manage"><a style="text-decoration:none" onClick="product_brand_edit('品牌编辑','codeing.html','1')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="active_del(this,'10001')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
               </tr>
               </thead>-->
            </tbody>
        </table>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var url=decodeURI(decodeURI(window.location.search));
        var r = url.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    /*自己修改 lyx*/
    $(function(){
        // 学号
        // var id = getQueryString("id");
        var clazz = getQueryString("clazz");
        $.ajax({
            url: "http://fantj.top:8081/dormitory/getListByClazz/"+clazz,
            type: "get",
            async: true,
            success: function (result) {
                console.log(result);
                get_list(result.data);
            }
        });
    });

    function get_list(result) {
        var str = $('<thead>'+
            '<tr class="text-c">'+
            '<th >公寓号</th>'+
            '<th >宿舍号</th>'+
            '<th >已有人数</th>'+
            '<th>操作</th>'+
            '</tr>'+
            '</thead>');
        $('#list').empty();
        $.each(result,function (index,item) {
            var aptId = $('<td></td>').append(item.aptId);
            var dorId= $('<td></td>').append(item.dorNum);
            var peoples = $('<td></td>').append(item.peoples);
            var option = $('<td class="td-manage"> <a title="编辑" href="javascript:;" onclick="insertInfo('+item.aptId+','+item.dorId+')" class="ml-5" style="text-decoration:none">&nbsp;&nbsp;&nbsp;&nbsp;加入<i class="Hui-iconfont">&#xe600;</i></td>');
            var head =  $('<tr></tr>').addClass("text-c");
            var prethead = $('<thead></thead>');
            str.append(prethead).append(head).append(aptId).append(dorId).append(peoples).append(option).appendTo('#list');
        })
    }

    function insertInfo(aptId,dorId) {
        var id = getQueryString("id");
        alert("Submitted");
        var json = {
            "aptId": aptId,
            "dorId": dorId,
            "stuId":id
        };
        // alert(json)
        $.ajax({
            //提交数据的类型 POST GET
            type:"POST",
            //提交的网址
            url:"http://127.0.0.1:8081/studor/add",
            //提交的数据
            data:json,
            //返回数据的格式
            dataType: "json",//"xml", "html", "script", "json", "jsonp", "text".
            async: false,
            success:function(data){
                console.log(data);
                alert("添加成功!")
            }   ,
            error: function(){
                alert("添加失败");
            }
        });
        var index = parent.layer.getFrameIndex(window.name);
        parent.$('.btn-refresh').click();
        parent.layer.close(index);
    }

</script>
</body>
</html>